package cn.qxq1.springevent.event;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.stereotype.Component;

@Component
//@EnableAsync 这里可以  但是不能实现applicationListener接口
public class MyEventPublisher implements ApplicationContextAware {
    private ApplicationContext context;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

    public void publish(ApplicationEvent event) {
        context.publishEvent(event);
    }
}
